<?php

class WeddingServiceModel extends MY_Model {
	function WeddingServiceModel() {
		parent::MY_Model ( 'wedding_service' );
	}
	
	/**
	 * save image
	 * @param unknown_type $wedding form wedding
	 * @param unknown_type $img_path img path
	 */
	function update_img($wedding) {
		$str_img = "";
		$db_wedding = $this->get_one ( $wedding ['id'] );
		if ($db_wedding) {
			if (isset ( $db_wedding ['img'] )) {
				if (trim ( $db_wedding ['img'] ) != "") {
					$wedding ['img'] = $db_wedding ['img'] . " " . $wedding ['img'];
					$str_img = $wedding ['img'];
				}
			}
		}
		$this->update ( $wedding ['id'], $wedding );
		if ($str_img == "") {
			return $wedding ['img'];
		}
		return $str_img;
	}
	
	function delete_img($path, $id) {
		$db_wedding = $this->get_one ( $id );
		if ($db_wedding) {
			if (isset ( $db_wedding ['img'] )) {
				if (trim ( $db_wedding ['img'] ) != "") {
					
					$db_path = $db_wedding ['img'] ;
					$path_array = explode(" ", $db_path);
					
					for ($i = 0; $i < count($path_array); $i++) {
						if (strtolower(trim($path_array[$i])) == strtolower(trim($path))) {
							unset($path_array[$i]);
							break;
						}
					}
					$new_img_str = implode(" ", $path_array);
					$this->update($id, array('img' => $new_img_str));
				
				}
			}
		}
	}
}

?>